package com.only4play.usercenter.config;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

/**
 * @author liyuncong
 * @version 1.0
 * @file ApplicationServerConfiguration
 * @brief 应用服务配置
 * @details 应用服务配置
 * @date 2024-05-21
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                     NAME               DESCRIPTION
 * 2024-05-21               liyuncong          Created
 */

@Slf4j
@Component
@Getter
public class ApplicationServerConfiguration implements ApplicationListener<ApplicationStartedEvent> {

    /**
     * 服务端口
     */
    private String serverPort;

    /**
     * 服务IP
     */
    private String serverIp;

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        try {
            this.serverPort = event.getApplicationContext().getEnvironment().getProperty("server.port");
            this.serverIp = InetAddress.getLocalHost().getHostAddress();
        } catch (Exception e) {
            log.error("ApplicationServerConfiguration onApplicationEvent", e);
        }
    }
}
